import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate' // vuex持久化存储
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import routers from './modules/routers'
import tagsView from './modules/tagsView'

Vue.use(Vuex)

const store = new Vuex.Store({
  plugins: [createPersistedState({ // vuex持久化存储
    storage: window.sessionStorage,
    reducer(val) {
      console.log(111, val)
      return {
        user: {
          reLogin: val.user.reLogin // 持久化存储重新登陆
        },
        routers: { 
          asyncRoutes: val.routers.asyncRoutes, // 持久化存储动态路由
          routes: val.routers.routes, // 持久化存储全部路由
        },
        tagsView: {
          // visitedViews: val.tagsView.visitedViews, // 持久化存储历史记录页面
        }
      }
    }
  })],
  modules: {
    app,
    settings,
    user,
    routers,
    tagsView
  },
  getters
})

export default store

